package cn.waxcc.controller;

import cn.waxcc.config.MsmConstantUtils;
import cn.waxcc.pojo.Test;
import cn.waxcc.service.TestService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: springboot-medicalapp
 * @ClassName TestController
 * @description:
 * @author: JYF
 * @create: 2023-03-20 15:30
 * @Version 1.0
 */
@Api(tags = "用户管理")
@Controller
@CrossOrigin(origins = "*") //表示该类的所有方法允许跨域
//@RestController // 通常返回一个json或 字符串
public class TestController {

   /* @PostMapping("/login")
    public void login(String phone, String password) {
        if ("19808006488".equals(phone) && "123456".equals(password)) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
    }*/


   /* @GetMapping("/top")
    public String top(){
        return "top";
    }
    @GetMapping("/leftnav")
    public String leftnav(){
        return "leftnav";
    }


    @Autowired
    private TestService testService;

    @RequestMapping("/test")
    public String test(String phone){
        MsmConstantUtils.sendPhone(MsmConstantUtils.generateValidateCode(6),phone);
        return "success";
    }

    @GetMapping("/show")
    @ApiOperation(value = "所有用户信息")
    public List<Test> show() {
        List<Test> all = testService.findAll();
        System.out.println(all);
        return all;
    }

    @RequestMapping("/user")
    public String queryUser(Model model){
        List<Test> users = testService.findAll();
        model.addAttribute("user",users);
        return "allUser";
    }

    @RequestMapping("/allByPage")
    @ApiOperation(value = "分页用户信息")
    public String allBookByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "2") Integer pageSize,//设置默认页面大小为5
                                Model model){
        //为了程序的严谨性，判断非空：
        if(pageNum == null){//若pageNum为空
            pageNum = 1;   //设置默认当前页为1
        }
        if(pageNum <= 0){  //若为负数
            pageNum = 1;   //设置默认值为1
        }
        if(pageSize == null){ //若页面大小为空
            pageSize = 2;    //设置默认每页显示的数据数
        }
        try {
            //调用分页查询的方法
            List<Test> users = testService.queryUserByPage(pageNum,pageSize);
            model.addAttribute("user",users);//查询出的数据传到前端
            PageInfo pageInfo = new PageInfo(users,pageSize);//设置页面大小
            model.addAttribute("pageInfo",pageInfo);//将页面信息传到前端
        }finally {
            PageHelper.clearPage(); //清理 ThreadLocal 存储的分页参数,保证线程安全
        }
        return "allUser";
    }
*/

}
